package yto.freemarker.springaop.cglib;

import org.springframework.cglib.proxy.Enhancer;
import yto.freemarker.springaop.service.UserService;

/**
 * @author dongxing
 **/
public class MyCglibTest {

    public static void main(String[] args) {

        //1.代理对象生成器(工厂思想)
        Enhancer enhancer = new Enhancer();
        //2.在增强器上设置两个属性
        //设置要生成代理对象的目标对象：生成的目标对象类型的子类型
        enhancer.setSuperclass(UserService.class);
        //设置回调方法
        enhancer.setCallback(new MyMethodInterceptor());
        //3.创建获取对象
        UserService userService = (UserService) enhancer.create();
        userService.query();
    }
}
